package com.gxa.controller.municipalsys;


import com.gxa.common.R;
import com.gxa.entity.CitySysOrganization;
import com.gxa.service.CitySysOrganizationService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

@Controller
@Api(value = "市级机构管理",tags ="市级机构管理接口API")
@RequestMapping("/city_sys_organization")
public class CityOrganizationController {

    @Autowired
    private CitySysOrganizationService citySysOrganizationService;

    /**
     * 分页查询所有机构列表
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/findorganizations",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "查询所有机构接口",notes = "查询所有机构",httpMethod = "POST", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "每页数据条数",paramType = "query",dataType = "int",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=401,message="token为空"),
            @ApiResponse(code=1005,message="Token过期"),
            @ApiResponse(code=1006,message="Token验证不通过"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R findAllOrganization(Integer currentPage,Integer pageSize){

        return citySysOrganizationService.findOrganizations(currentPage,pageSize);
    }

    /**
     * 根据机构名，管理员，联系方式多条件查询机构列表
     * @param currentPage
     * @param pageSize
     * @param orgName
     * @param adminName
     * @param adminPhone
     * @return
     */
    @RequestMapping(value = "/findorganizationbyconditions",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "根据条件查询机构接口",notes = "根据条件查询机构",httpMethod = "POST", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页",required = true,paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "pageSize",value = "每页数据条数",required = true,paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "orgName",value = "机构名称",required = false,paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "adminName",value = "管理员名称",required = false,paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "adminPhone",value = "联系方式",required = false,paramType = "query",dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=401,message="token为空"),
            @ApiResponse(code=1005,message="Token过期"),
            @ApiResponse(code=1006,message="Token验证不通过"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R findOrgnizationByConditions( Integer currentPage, Integer pageSize, String orgName , String adminName , String adminPhone){



        return citySysOrganizationService.findOrgnizationByConditions(currentPage,pageSize,orgName,adminName,adminPhone);
    }

    /**
     * 根据机构编号查询机构
     * @param id
     * @return
     */
    @RequestMapping(value = "/findorganizationbyid",method = RequestMethod.POST)
    @ResponseBody
    public R findorganizationbyid(Integer id){
        return citySysOrganizationService.findorganizationbyid(id);
    }


    /**
     * 添加机构
     * @param citySysOrganization
     * @return
     */
    @RequestMapping(value = "/addorganization",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "添加机构接口",notes = "添加机构",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=401,message="token为空"),
            @ApiResponse(code=1005,message="Token过期"),
            @ApiResponse(code=1006,message="Token验证不通过"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R addOrgnization(@RequestBody @ApiParam(name = "CitySysOrganization",value = "市级系统机构信息",required = true) CitySysOrganization citySysOrganization){


    return citySysOrganizationService.addorganization(citySysOrganization);
    }

    /**
     * 编辑机构
     * @param citySysOrganization
     * @return
     */
    @RequestMapping(value = "/updateorganization",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "修改机构接口",notes = "修改机构",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=401,message="token为空"),
            @ApiResponse(code=1005,message="Token过期"),
            @ApiResponse(code=1006,message="Token验证不通过"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateorganization(@RequestBody @ApiParam(name = "CitySysOrganization",value = "市级系统机构信息",required = true) CitySysOrganization citySysOrganization){

        return citySysOrganizationService.updateorganization(citySysOrganization);
    }

    /**
     * 根据机构编号删除机构
     * @param orgId
     * @return
     */
    @RequestMapping(value = "/deleteorganization",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "删除机构接口",notes = "删除机构",httpMethod = "POST", response = R.class)
    @ApiImplicitParam(name = "orgId",value = "机构编号",required = true,paramType = "query",dataType = "int")
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=401,message="token为空"),
            @ApiResponse(code=1005,message="Token过期"),
            @ApiResponse(code=1006,message="Token验证不通过"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R deleteorganization(Integer orgId){


        return citySysOrganizationService.deleteorganization(orgId);
    }


    /**
     * 重置机构管理员密码为123456
     * @param orgId
     * @return
     */
    @RequestMapping(value = "/resetpassword",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "重置密码接口",notes = "重置密码",httpMethod = "POST", response = R.class)
    @ApiImplicitParam(name = "orgId",value = "机构编号",required = true,paramType = "query",dataType = "int")
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=401,message="token为空"),
            @ApiResponse(code=1005,message="Token过期"),
            @ApiResponse(code=1006,message="Token验证不通过"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R resetpassword(Integer orgId){

        return citySysOrganizationService.resetpassword(orgId);
    }

}
